<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
      <title>Mission Panel | HiAPI-C# 2025 </title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="title" content="Mission Panel | HiAPI-C# 2025 ">
      
      
      <link rel="icon" href="../../../../img/HiAPI.favicon.ico">
      <link rel="stylesheet" href="../../../../public/docfx.min.css">
      <link rel="stylesheet" href="../../../../public/main.css">
      <meta name="docfx:navrel" content="../../../../toc.html">
      <meta name="docfx:tocrel" content="../../toc.html">
      
      <meta name="docfx:rel" content="../../../../">
      
      
      
      <meta name="loc:inThisArticle" content="In this article">
      <meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
      <meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
      <meta name="loc:tocFilter" content="Filter by title">
      <meta name="loc:nextArticle" content="Next">
      <meta name="loc:prevArticle" content="Previous">
      <meta name="loc:themeLight" content="Light">
      <meta name="loc:themeDark" content="Dark">
      <meta name="loc:themeAuto" content="Auto">
      <meta name="loc:changeTheme" content="Change theme">
      <meta name="loc:copy" content="Copy">
      <meta name="loc:downloadPdf" content="Download PDF">

      <script type="module" src="./../../../../public/docfx.min.js"></script>

      <script>
        const theme = localStorage.getItem('theme') || 'auto'
        document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
      </script>

  </head>

  <body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
    <header class="bg-body border-bottom">
      <nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
        <div class="container-xxl flex-nowrap">
          <a class="navbar-brand" href="../../../../index.html">
            <img id="logo" class="svg" src="../../../../img/HiAPI.logo.png" alt="">
            
          </a>
          <button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
            <i class="bi bi-three-dots"></i>
          </button>
          <div class="collapse navbar-collapse" id="navpanel">
            <div id="navbar">
              <form class="search" role="search" id="search">
                <i class="bi bi-search"></i>
                <input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
              </form>
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="container-xxl">
      <div class="toc-offcanvas">
        <div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body">
            <nav class="toc" id="toc"></nav>
          </div>
        </div>
      </div>

      <div class="content">
        <div class="actionbar">
          <button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
            <i class="bi bi-list"></i>
          </button>

          <nav id="breadcrumb"></nav>
        </div>

        <article data-uid="">
          <h1 id="mission-panel">Mission Panel</h1>

<p>The <code>Mission Panel</code> manages NC program loading, editing, and preparation for simulation in the geometry-only HiNC application.</p>
<h2 id="panel-layout">Panel Layout</h2>
<ul>
<li><p>Left side: <code>NC Program Management Panel</code></p>
<ul>
<li><code>Program Files Section</code>
<ul>
<li><code>Load NC File</code> button</li>
<li><code>New NC File</code> button</li>
<li>List view of loaded NC programs</li>
<li><code>Remove</code> button (to remove selected program)</li>
</ul>
</li>
<li><code>Program Properties Section</code>
<ul>
<li>File name and path display</li>
<li>Program description input field</li>
<li>Program size and line count display</li>
</ul>
</li>
<li><code>Program Association Section</code>
<ul>
<li>Tool mapping controls:
<ul>
<li>Dropdown to select T-code</li>
<li>Dropdown to select corresponding tool from Tool House</li>
<li><code>Apply Mapping</code> button</li>
</ul>
</li>
<li>Work offset mapping controls:
<ul>
<li>Dropdown to select work offset code (G54, G55, etc.)</li>
<li>X, Y, Z offset value inputs</li>
<li><code>Apply Offset</code> button</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Right side: <code>NC Program Editor/Viewer</code></p>
<ul>
<li>Syntax-highlighted G-code editor</li>
<li>Line numbers</li>
<li><code>Save</code> button</li>
<li><code>Validate</code> button</li>
<li>Validation results display area</li>
<li><code>Show Toolpath Preview</code> toggle button</li>
</ul>
</li>
<li><p>Bottom: <code>Toolpath Preview Panel</code> (shown when preview is toggled on)</p>
<ul>
<li>3D view of the toolpath</li>
<li>Color-coded display based on operation type or feed rate</li>
<li>Basic camera controls</li>
</ul>
</li>
</ul>
<h2 id="behavior">Behavior</h2>
<h3 id="loading-nc-program-files">Loading NC Program Files</h3>
<p>When the user clicks the <code>Load NC File</code> button:</p>
<ol>
<li>Open a file selection dialog showing NC files (*.nc, *.cnc, *.ngc, etc.)</li>
<li>After selection, validate the file format</li>
<li>Add the file to the list of NC programs</li>
<li>Display the file in the editor/viewer</li>
<li>Update program properties display</li>
</ol>
<pre><code class="lang-csharp">// Example code
public void LoadNCFile(string filePath)
{
    if (File.Exists(filePath))
    {
        // Read and validate NC file
        string programContent = File.ReadAllText(filePath);
        
        // Create a new program object
        NCProgram program = new NCProgram
        {
            FilePath = filePath,
            FileName = Path.GetFileName(filePath),
            Content = programContent,
            LineCount = programContent.Split('\n').Length,
            FileSize = new FileInfo(filePath).Length
        };
        
        // Add to the project's mission
        machiningProject.MachiningMission.Programs.Add(program);
        
        // Update the NC program list view
        UpdateProgramListView();
        
        // Select the newly added program
        SelectProgram(program);
        
        // Display the program in the editor
        LoadProgramIntoEditor(program);
    }
}
</code></pre>
<h3 id="creating-a-new-nc-program">Creating a New NC Program</h3>
<p>When the user clicks the <code>New NC File</code> button:</p>
<ol>
<li>Create a new empty NC program object</li>
<li>Add it to the list of programs</li>
<li>Load it into the editor with minimal template content</li>
<li>Allow the user to start editing</li>
</ol>
<pre><code class="lang-csharp">public void CreateNewNCProgram()
{
    // Create a basic template for a new NC program
    string templateContent = &quot;%\nO0001\n(NEW PROGRAM)\n\nG90 G40 G17\nG21 (MM)\n\n(PROGRAM BODY)\n\nM30\n%&quot;;
    
    // Create a new program object
    NCProgram program = new NCProgram
    {
        FileName = &quot;NewProgram.nc&quot;,
        Content = templateContent,
        LineCount = templateContent.Split('\n').Length,
        IsNew = true
    };
    
    // Add to the project's mission
    machiningProject.MachiningMission.Programs.Add(program);
    
    // Update the NC program list view
    UpdateProgramListView();
    
    // Select the newly added program
    SelectProgram(program);
    
    // Display the program in the editor
    LoadProgramIntoEditor(program);
}
</code></pre>
<h3 id="tool-mapping">Tool Mapping</h3>
<p>When the user sets up a tool mapping and clicks <code>Apply Mapping</code>:</p>
<ol>
<li>Extract the T-code from the selected dropdown</li>
<li>Get the corresponding tool from the Tool House based on the selection</li>
<li>Add or update the mapping in the mission's tool map</li>
<li>Update the display to show the active mapping</li>
</ol>
<pre><code class="lang-csharp">public void ApplyToolMapping(string tCodeStr, int toolHousePosition)
{
    if (int.TryParse(tCodeStr.Substring(1), out int tCode))
    {
        // Get the tool from the tool house
        var tool = machiningProject.MachiningToolHouse[toolHousePosition];
        if (tool != null)
        {
            // Update or add the mapping
            machiningProject.MachiningMission.ToolMap[tCode] = toolHousePosition;
            
            // Update the display
            UpdateToolMappingDisplay();
        }
    }
}
</code></pre>
<h3 id="work-offset-mapping">Work Offset Mapping</h3>
<p>When the user sets up a work offset and clicks <code>Apply Offset</code>:</p>
<ol>
<li>Extract the offset code (G54, G55, etc.)</li>
<li>Create a vector from the X, Y, Z input values</li>
<li>Add or update the offset in the mission's work offset map</li>
<li>Update the display to show the active offset</li>
</ol>
<pre><code class="lang-csharp">public void ApplyWorkOffset(string offsetCode, double x, double y, double z)
{
    // Create the offset vector
    Vec3d offset = new Vec3d(x, y, z);
    
    // Update or add the mapping
    machiningProject.MachiningMission.WorkOffsetMap[offsetCode] = offset;
    
    // Update the display
    UpdateWorkOffsetDisplay();
}
</code></pre>
<h3 id="validating-nc-program">Validating NC Program</h3>
<p>When the user clicks the <code>Validate</code> button:</p>
<ol>
<li>Parse the current program content in the editor</li>
<li>Check for syntax errors</li>
<li>Verify tool references against the tool map</li>
<li>Check for unsupported G/M codes</li>
<li>Display validation results in the results area</li>
</ol>
<pre><code class="lang-csharp">public void ValidateProgram()
{
    // Get the current content from the editor
    string programContent = GetEditorContent();
    
    // Create a validator
    NCProgramValidator validator = new NCProgramValidator(machiningProject);
    
    // Perform validation
    ValidationResult result = validator.Validate(programContent);
    
    // Display results
    ClearValidationResultsDisplay();
    if (result.IsValid)
    {
        DisplayValidationSuccess(&quot;Program validation successful.&quot;);
    }
    else
    {
        foreach (var error in result.Errors)
        {
            DisplayValidationError(error);
        }
    }
}
</code></pre>
<h3 id="displaying-toolpath-preview">Displaying Toolpath Preview</h3>
<p>When the user toggles the <code>Show Toolpath Preview</code>:</p>
<ol>
<li>If toggled on:
a. Parse the NC program
b. Generate a toolpath using the geometry-only simulation engine
c. Render the toolpath in the preview panel
d. Show the preview panel</li>
<li>If toggled off:
a. Hide the preview panel</li>
</ol>
<pre><code class="lang-csharp">public void ToggleToolpathPreview(bool showPreview)
{
    if (showPreview)
    {
        // Get the current program
        NCProgram program = GetSelectedProgram();
        
        // Generate toolpath (simplified for geometry-only)
        Toolpath toolpath = ToolpathGenerator.GenerateFromNCProgram(
            program.Content, 
            machiningProject.MachiningMission.ToolMap,
            machiningProject.MachiningMission.WorkOffsetMap,
            machiningProject.MachiningEquipment);
        
        // Render the toolpath
        RenderToolpathPreview(toolpath);
        
        // Show the preview panel
        toolpathPreviewPanel.Visibility = Visibility.Visible;
    }
    else
    {
        // Hide the preview panel
        toolpathPreviewPanel.Visibility = Visibility.Collapsed;
    }
}
</code></pre>
<h3 id="data-structure">Data Structure</h3>
<p>The panel operates primarily on the <code>MachiningMission</code> of the <code>MachiningProject</code>:</p>
<pre><code class="lang-csharp">public class MachiningMission
{
    public List&lt;NCProgram&gt; Programs { get; set; } = new List&lt;NCProgram&gt;();
    public Dictionary&lt;int, int&gt; ToolMap { get; set; } = new Dictionary&lt;int, int&gt;();
    public Dictionary&lt;string, Vec3d&gt; WorkOffsetMap { get; set; } = new Dictionary&lt;string, Vec3d&gt;();
    // Other mission-related properties
}

public class NCProgram
{
    public string FilePath { get; set; }
    public string FileName { get; set; }
    public string Content { get; set; }
    public long FileSize { get; set; }
    public int LineCount { get; set; }
    public bool IsNew { get; set; }
    public string Description { get; set; }
    // Other program-related properties
}
</code></pre>
<h2 id="integration-with-main-application">Integration with Main Application</h2>
<p>The <code>Mission Panel</code> is activated when the user selects the <code>Mission</code> item in the <code>Navigation Menu</code>. It accesses and modifies the <code>MachiningMission</code> component of the current <code>MachiningProject</code> instance.</p>
<p>When changes are made in this panel, the following notifications should be sent:</p>
<ol>
<li><code>ProgramListChanged</code> - When programs are added or removed</li>
<li><code>ProgramContentChanged</code> - When program content is edited</li>
<li><code>ToolMapChanged</code> - When tool mappings are updated</li>
<li><code>WorkOffsetMapChanged</code> - When work offsets are updated</li>
</ol>
<p>These notifications allow other components (particularly the Player panel) to update their behavior accordingly when preparing for or executing the simulation.</p>

</article>

        <div class="contribution d-print-none">
        </div>

        <div class="next-article d-print-none border-top" id="nextArticle"></div>

      </div>

      <div class="affix">
        <nav id="affix"></nav>
      </div>
    </main>

    <div class="container-xxl search-results" id="search-results"></div>

    <footer class="border-top text-secondary">
      <div class="container-xxl">
        <div class="flex-fill">
          <span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
        </div>
      </div>
    </footer>
  </body>
</html>
